home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / Utilities / Interfaces / SIHshTbl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-22  |  3.8 KB  |  135 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        SIHshTbl.h
  3.  
  4.     Contains:    Interface to hash table code and SIHashTable class.
  5.  
  6.     Owned by:    Nick Pilch
  7.  
  8.     Copyright:    © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     
  11. */
  12.  
  13. #ifndef _SIHSHTBL_
  14. #define _SIHSHTBL_
  15.  
  16. #ifndef _ODTYPES_
  17. #include "ODTypes.h"
  18. #endif
  19.  
  20. #ifndef _PLFMDEF_
  21. #include "PlfmDef.h"
  22. #endif
  23.  
  24. //==============================================================================
  25. // Theory of Operation
  26. //==============================================================================
  27.  
  28. /*
  29.     C Interface to some of the routines in HashTabl.A and class wrapper.
  30.  
  31.     The class simply provides an object-oriented wrapper to the AE hash table
  32.     functions found in HashTable.A. It removes access to the MemHooks parameter. (MemHooks is set to NULL and SysHeap is set to false.)
  33.     It hides the Table parameter since that is a member variable of the class.
  34. */
  35.  
  36. //==============================================================================
  37. // Scalar Types
  38. //==============================================================================
  39.  
  40. typedef void* ODEntryPtr;
  41. typedef void* ODKeyPtr;
  42. typedef    Handle HashTable;
  43.  
  44.  
  45. //==============================================================================
  46. // Error Codes
  47. //==============================================================================
  48.  
  49. const ODSShort kAEErrAlreadyExists    = -1722;
  50. const ODSShort kAEErrNotFound        = -1723;
  51. const ODSShort kAEErrEndOfTable    = -1724;
  52.  
  53.  
  54. //==============================================================================
  55. // Classes defined in this interface
  56. //==============================================================================
  57.  
  58. class SIHashTable;
  59. class SIHashTableIterator;
  60.  
  61. //==============================================================================
  62. // SIHashTable
  63. //==============================================================================
  64.  
  65. class SIHashTable
  66. {    
  67.     friend class SIHashTableIterator;
  68.  
  69.   public:
  70.  
  71.     SIHashTable();
  72.     ODVMethod void Initialize(ODULong numEntries, ODUShort keySize,
  73.                                 ODUShort valueSize, ODBoolean inSysHeap);
  74.         // kODErrOutOfMemory is thrown if the table cannot be created.
  75.  
  76.     virtual ~SIHashTable();
  77.  
  78.     ODVMethod void            ReplaceEntry(ODKeyPtr key, ODEntryPtr value);
  79.         // Replace and/or add an entry. Pass a POINTER to the key as well as a
  80.         //    a POINTER to the value to be added. kODErrOutOfMemory is thrown if
  81.         //    the entry cannot be added.
  82.  
  83.     ODVMethod void            RemoveEntry(ODKeyPtr key);
  84.         // Pass a POINTER to the key.
  85.  
  86.     ODVMethod ODBoolean    GetValue(ODKeyPtr key, ODEntryPtr value);
  87.         // Pass a POINTER to the key as well as a POINTER to the value to be
  88.         //    retrieved. kODTrue is returned if the key was found, kODFalse
  89.         //    otherwise.
  90.         
  91.     ODVMethod ODBoolean    Exists(ODKeyPtr key);
  92.         // Check to see if a key exists. This function is no faster than
  93.         //    GetValue and should probably only be used when you do not intend to
  94.         //    fetch the value immediately. kODTrue is returned if the key exists,
  95.         //    kODFalse, otherwise.
  96.     
  97.   protected:
  98.  
  99.     HashTable    fSIHashTable;
  100.     ODUShort     fValueSize;
  101.     
  102.     HashTable    GetSIHashTable();
  103. };
  104.  
  105. //==============================================================================
  106. // SIHashTableIterator
  107. //
  108. //    This iterator is only meant to be used in the the context of a for loop,
  109. //    e.g.:
  110. //
  111. //    SIHashTableIterator iter;
  112. //    for (iter.First(key, value); iter.IsNotComplete(); iter.Next(key, value))
  113. //    {
  114. //        ...
  115. //    }
  116. //
  117. //==============================================================================
  118.  
  119. class SIHashTableIterator
  120. {
  121.   public:
  122.     SIHashTableIterator(SIHashTable* table);
  123.     ~SIHashTableIterator();
  124.     
  125.     void            First(ODKeyPtr key, ODEntryPtr value);
  126.     void            Next(ODKeyPtr key, ODEntryPtr value);
  127.     ODBoolean        IsNotComplete();
  128.   private:
  129.     SIHashTable* fTable;
  130.     ODSLong        fIndex;
  131.     ODBoolean        fDone;
  132.     ODBoolean        GetNext(ODKeyPtr key, ODEntryPtr value);
  133. };
  134.  
  135. #endif // _SIHSHTBL_